package com.kalix.btzjjj.memory.api.model;

//import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import org.apache.camel.json.simple.JsonObject;
import org.json.JSONArray;
import org.json.JSONObject;

import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;

public class HttpRequestUtil {

    public static String getXpath(String requestUrl){
        String res="";
//        JSONObject object = null;
//        JSONArray array = null;
        StringBuffer buffer = new StringBuffer();
        try{
            URL url = new URL(requestUrl);
            HttpURLConnection urlCon= (HttpURLConnection)url.openConnection();
            urlCon.setConnectTimeout(600000);
            // System.out.println("response code:" + urlCon.getResponseCode());
            if(200==urlCon.getResponseCode()){
                InputStream is = urlCon.getInputStream();
                InputStreamReader isr = new InputStreamReader(is,"utf-8");
                BufferedReader br = new BufferedReader(isr);

                String str = null;

                while((str = br.readLine())!=null){
                    buffer.append(str);
                }
                br.close();
                isr.close();
                is.close();
                res = buffer.toString();


//                object = (JsonObject) parse.parse(res);
//                JsonParser parse =new JsonParser();
//                object = new JSONObject(res);
                // object = (JsonObject) parse.parse(res);
            }
        }catch(IOException e){
            e.printStackTrace();
        }
        return res;
    }


}
